<template>
  <div>
    <router-link
      to="/"
      tag="div"
      class="header-abs"
      v-show="!showAbs">
      <font-awesome-icon :icon="['fas', 'chevron-left']"/>
    </router-link>
    <div class="header-fixed" :style="opacityStyle" v-show="showAbs">
      <router-link to="/" tag="div" class="header-left">
        <font-awesome-icon :icon="['fas', 'chevron-left']" size="lg"/>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'Header',
  data() {
    return {
      showAbs: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll(e) {
      console.log('scrool')
      const top = document.documentElement.scrollTop
      if (top > 30) {
        this.showAbs = true
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle.opacity = opacity
      } else {
        this.showAbs = false
      }
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll)
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-abs
    width .5rem
    height .5rem
    line-height .5rem
    position absolute
    top .2rem
    left .2rem
    z-index 10
    color #fff
    border-radius 50%
    background-color rgba(0, 0, 0, .5)
    text-align center

  .header-fixed
    position fixed
    z-index 10
    width 100%
    height: 0.86rem
    line-height: 0.86rem
    background-color $bgColor
    text-align center
    color #fff

    .header-left
      float left
      width 0.64rem

</style>
